﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gota.Common.Entities.UI;

namespace Gota.Common.Annotations
{
    public class Annotation
    {
        private List<NameValueEntity> attributes;
        private List<Annotation> childAnnotations;

        public int Id { get; set; }
        public string Name { get; set; }
        public string ContentText { get; set; }
        public List<NameValueEntity> Attributes
        {
            get
            {
                if (attributes == null)
                {
                    attributes = new List<NameValueEntity>();
                }
                return attributes;
            }
        }
        public List<Annotation> ChildAnnotations
        {
            get
            {
                if (childAnnotations == null)
                {
                    childAnnotations = new List<Annotation>();
                }
                return childAnnotations;
            }
        }


        public void BuildAnnotationLabels(List<LabelInfo> infoList)
        {
            var existing = infoList.Where(o => String.Equals(o.Name, Name)).FirstOrDefault();
            if (existing == null)
            {
                LabelInfo lbl = new LabelInfo
                {
                    Name = this.Name,
                };
                lbl.Contents.Add(ContentText);
                if (String.IsNullOrEmpty(ContentText) == false)
                {
                    infoList.Add(lbl);
                }
            }
            else
            {
                existing.Contents.Add(ContentText);
            }
            foreach (var item in ChildAnnotations)
            {
                item.BuildAnnotationLabels(infoList);
            }
        }
    }
}
